/**************************************************
 *
 * Intrinsic functions for the IAR C/C++ Compiler
 * for Renesas SH.
 *
 * Copyright 2009-2010 IAR Systems AB.
 *
 * $Revision: 2 $
 *
 **************************************************/

#ifndef __INTRINSICS_H
#define __INTRINSICS_H

#pragma language=save
#pragma language=extended


/*
 * The return value of "__get_interrupt_state".
 */

typedef unsigned int istate_t;

#ifdef __cplusplus
extern "C"
{
#endif
  #define __enable_interrupt()  __set_interrupt_state(0)
  #define __disable_interrupt() __set_interrupt_state(15)

  __intrinsic istate_t __get_interrupt_state(void);
  __intrinsic void     __set_interrupt_state(istate_t);

  __intrinsic void   __set_interrupt_table(void * address);
  __intrinsic void * __get_interrupt_table(void);

  /* Special instruction intrinsics */
  __intrinsic void __no_operation(void);
  __intrinsic void __sleep(void);
  __intrinsic void __prefetch(void *address);

/* follow smachine.h */
#define _builtin_set_imask __set_interrupt_state  
  /*__intrinsic void _builtin_set_imask(unsigned int);*/
#define _builtin_get_imask __get_interrupt_state  
  /*__intrinsic unsigned int _builtin_get_imask(void);*/
  __intrinsic void   _builtin_set_cr(int);
  __intrinsic int    _builtin_get_cr(void);
  __intrinsic void   _builtin_set_vbr(void *);
  __intrinsic void * _builtin_get_vbr(void);
  
#define _builtin_sleep __sleep
  /*__intrinsic void _builtin_sleep(void);*/

/* follow umachine.h */
  __intrinsic void _builtin_set_gbr(void *);
  __intrinsic void *_builtin_get_gbr(void);
  __intrinsic unsigned char _builtin_gbr_read_byte(int);
  __intrinsic unsigned short _builtin_gbr_read_word(int);
  __intrinsic unsigned long _builtin_gbr_read_long(int);
  __intrinsic void _builtin_gbr_write_byte(int, unsigned char);
  __intrinsic void _builtin_gbr_write_word(int, unsigned short);
  __intrinsic void _builtin_gbr_write_long(int, unsigned long);
  __intrinsic void _builtin_gbr_and_byte(int, unsigned char);
  __intrinsic void _builtin_gbr_or_byte(int, unsigned char);
  __intrinsic void _builtin_gbr_xor_byte(int, unsigned char);
  __intrinsic int _builtin_gbr_tst_byte(int, unsigned char);
  __intrinsic int _builtin_tas(char *);
  __intrinsic int _builtin_macw(short *, short *, unsigned int);
  __intrinsic int _builtin_macwl(short *, short *, unsigned int, unsigned int);
  __intrinsic int _builtin_macl(int *, int *, unsigned int);
  __intrinsic int _builtin_macll(int *, int *, unsigned int, unsigned int);
#define _builtin_prefetch __prefetch
  /*__intrinsic void _builtin_prefetch(void *);*/
#define _builtin_nop __no_operation
  /*__intrinsic void _builtin_nop(void);*/
  __intrinsic unsigned short _builtin_swapb(unsigned short);
  __intrinsic unsigned long  _builtin_swapw(unsigned long);
  __intrinsic unsigned long  _builtin_end_cnvl(unsigned long);
  __intrinsic unsigned long  _builtin_dmulu_h(unsigned long, unsigned long);
  __intrinsic unsigned long  _builtin_dmulu_l(unsigned long, unsigned long);
  __intrinsic long _builtin_dmuls_h(long, long);
  __intrinsic unsigned long _builtin_dmuls_l(long, long);
  __intrinsic int _builtin_movt(void);
  __intrinsic unsigned long _builtin_xtrct(unsigned long, unsigned long);
  __intrinsic long _builtin_addc(long, long);
  __intrinsic int  _builtin_ovf_addc(long, long);
  __intrinsic long _builtin_addv(long, long);
  __intrinsic int  _builtin_ovf_addv(long, long);
  __intrinsic long _builtin_subc(long, long);
  __intrinsic int  _builtin_unf_subc(long, long);
  __intrinsic long _builtin_subv(long, long);
  __intrinsic int  _builtin_unf_subv(long, long);
  __intrinsic long _builtin_negc(long);
  __intrinsic unsigned long _builtin_div1(unsigned long, unsigned long);
  __intrinsic int  _builtin_div0s(long, long);
  __intrinsic void _builtin_div0u(void);
  __intrinsic unsigned long _builtin_rotl(unsigned long);
  __intrinsic unsigned long _builtin_rotr(unsigned long);
  __intrinsic unsigned long _builtin_rotcl(unsigned long);
  __intrinsic unsigned long _builtin_rotcr(unsigned long);
  __intrinsic unsigned long _builtin_shll(unsigned long);
  __intrinsic unsigned long _builtin_shlr(unsigned long);
  __intrinsic long _builtin_shar(long);
  __intrinsic void _builtin_clrt(void);
  __intrinsic void _builtin_sett(void);
  __intrinsic long _builtin_clipsb(long);
  __intrinsic long _builtin_clipsw(long);
  __intrinsic unsigned long _builtin_clipub(unsigned long);
  __intrinsic unsigned long _builtin_clipuw(unsigned long);
#define _builtin_set_tbr __set_interrupt_table
  /*__intrinsic void _builtin_set_tbr(void *);*/
#define _builtin_get_tbr __get_interrupt_table
  /*__intrinsic void *_builtin_get_tbr(void);*/


  __intrinsic float _builtin_fabsf(float);
  __intrinsic double _builtin_fabs(double);
#if __CORE__ == __SH2AFPU__  
  __intrinsic float _builtin_sqrtf(float);
  __intrinsic double _builtin_sqrt(double);
#else

#define _builtin_sqrtf(X) _Pragma("error \"_builtin_sqrtf needs fpu support\"") 0.0
#define _builtin_sqrt(X)  _Pragma("error \"_builtin_sqrt needs fpu support\"")  0.0

#endif

#ifdef __cplusplus
}
#endif


#pragma language=restore

#endif /* __INTRINSICS_H */
